package com.yyge.dao;

import java.sql.*;

public class BaseDao {
    private static final String DRIVER="com.mysql.jdbc.Driver";
    private static final String URL="jdbc:mysql://localhost:3306/trialpost";
    private static final String UID="root";
    private static final String PWD="admin";

    protected Connection conn;
    protected PreparedStatement sta;
    protected ResultSet rs;

    static {
        try {
            Class.forName(DRIVER);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
    public void open_db(){
        try {
            conn= DriverManager.getConnection(URL,UID,PWD);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    public void close_db(){
        try {
            if(rs!=null){rs.close();}
            if(sta!=null){sta.close();}
            if(conn!=null){conn.close();}
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }
}
